<?php

header('Content-type=text/html;charset=utf-8');
session_start();//开启session服务
include_once 'dbConfig.php';
include_once 'common.php';

if($_GET){
    if(isset($_GET['getType']) && $_GET['getType'] === 'confirmById'){
        $id = $_GET['conId'];
        $sql = 'select * from ywc_products where id = '.$id;
        $res = selectQuery($sql);
        if(count($res)>0){
            responseEvent($res);
        }
    }
    if(isset($_GET['getType']) && $_GET['getType'] === 'getOrder'){
        if (checkLogin()) {
            $username = $_SESSION['loginUserName'];
            $selectSql = 'select p.*,s.num,s.id as shopcart_id  from ywc_shopcart as s JOIN ywc_products as p on s.pro_id=p.id where  s.status=2 and s.username="' . $username . '"';
            $res = selectQuery($selectSql);
            if (count($res) > 0) {
                responseEvent($res);
            }
        }else{
            $msg = ['msg' => '请登录!', 'status' => 0];
            responseEvent($msg);
        }
    }
}

if($_POST){
    if(isset($_POST['postType']) && $_POST['postType'] ==='orderSubmit'){
        $updateSql = 'update ywc_shopcart set status = 3 where pro_id = '.$_POST['pro_id'];
        if($link->query($updateSql)){
            responseEvent($msg);
        }
    }
    if(isset($_POST['postType']) && $_POST['postType'] ==='init'){
        $updateSql = 'update ywc_shopcart set status = 3 where pro_id = '.$_POST['pro_id'];
        if($link->query($updateSql)){
            responseEvent($msg);
        }
    }
}